const express = require('express');
const router = express.Router();
const Database = require('../model/connectDatabase');
const {SuccessModel,ErrorModel} = require('../model/resData');

//接受的参数title,describeStr,audioUrl,videoUrl,id
router.post('/', function(req, res, next) {
  let database = new Database().mysql;
  let sql = 'update resources set title=?,describeStr=?,audioUrl=?,videoUrl=? where(id=?)'
  let {title,describeStr,audioUrl,videoUrl,id} = req.body
  let msg = [title,describeStr,audioUrl,videoUrl,id]
  database.query(sql,msg,(error,response)=>{
    if(response.affectedRows != 0){
      res.send(new SuccessModel(response,'更新成功'))
    }else{
      res.send(new ErrorModel(response,'更新失败'))
    }
    if(error){
      res.send(new ErrorModel(error,'数据库访问失败'))
    }
  })
});

module.exports = router; 
